package com.china08.yxyapi.service.manage.tec.teaching.lecture.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.china08.yxyapi.entity.mg.esbag.test.YxyEsbagTeachingTestQuesStu;
import com.china08.yxyapi.service.manage.tec.teaching.lecture.LectureReportClassJudgeService;

@Service
public class LectureReportClassJudgeServiceImpl implements LectureReportClassJudgeService {

    @Override
    public List<YxyEsbagTeachingTestQuesStu> judgeChoiceQuestion(List<YxyEsbagTeachingTestQuesStu> list) {
        for (YxyEsbagTeachingTestQuesStu yxyEsbagTeachingTestQuesStu : list) {
            if ("1".equals(yxyEsbagTeachingTestQuesStu.getQuesType())) {
                // 单选
                if (yxyEsbagTeachingTestQuesStu.getAnswerOfQues().equals(yxyEsbagTeachingTestQuesStu.getAnswerOfMy())) {
                    yxyEsbagTeachingTestQuesStu.setPassed(1);
                } else {
                    yxyEsbagTeachingTestQuesStu.setPassed(0);
                }
            } else if ("8".equals(yxyEsbagTeachingTestQuesStu.getQuesType())) {
                // 多选
                String answerOfQues = yxyEsbagTeachingTestQuesStu.getAnswerOfQues();
                String[] split = answerOfQues.split(",");
                String linshiString = "";
                if (split.length == 1) {
                    yxyEsbagTeachingTestQuesStu.setPassed(0);
                } else {
                    for (int i = 0; i < split.length; i++) {
                        linshiString = linshiString + split[i].charAt(0) + ",";
                    }
                    answerOfQues = linshiString.substring(0, linshiString.length() - 1);
                    if (answerOfQues.equals(yxyEsbagTeachingTestQuesStu.getAnswerOfMy())) {
                        yxyEsbagTeachingTestQuesStu.setPassed(1);
                    } else {
                        yxyEsbagTeachingTestQuesStu.setPassed(0);
                    }
                }
            }
        }
        return list;
    }

}
